package com.testing.thread;

/**
 * @author Administrator
 */
public class TestVolatile implements Runnable {

    /**volatile 多线程时，同步属性的值，如果方法中使用了synchronized，则属性可以不用使用volatile**/
    private volatile int count = 10;

    @Override
    public void run() {
        count --;
        System.out.println(Thread.currentThread().getName() + "count = " + count);
    }

    public static void main(String[] args) {
        TestVolatile testVolatile = new TestVolatile();
        for (int i = 0; i < 100; i++) {
            new Thread(testVolatile).start();
        }
    }
}
